package com.yomahub.liteflow.example.threadproject;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * 验证动态任务队列扩容后，正常执行
 */
public class Demo2 {
    public static void main(String[] args) throws InterruptedException {
        ResizeableCapacityLinkedBlockingQueue<Object> blockingQueue = new ResizeableCapacityLinkedBlockingQueue<>(5);

        ExecutorService executor = Executors.newFixedThreadPool(1);
        executor.execute(() -> {
            for (int i = 0; i < 10; i++) {
                try {
                    blockingQueue.put(i);
                    System.out.println("put" + i + "成功后，的剩余容量："+ blockingQueue.remainingCapacity());
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });


        TimeUnit.SECONDS.sleep(3);

        blockingQueue.setCapacity(10);

        System.out.println(Thread.currentThread().getName() + " - setCapacity后的剩余容量："+ blockingQueue.remainingCapacity());




    }
}        // 创建一个线程池，用于执行异步任务
//        ThreadPoolExecutor executor = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(1));
//        // 创建一个异步任务
//        AsyncTask asyncTask = new AsyncTask(executor);
//        // 执行异步任务
//        asyncTask.execute(); CompletableFuture<Void> future = CompletableFuture.runAsync(() -> {
